<?php

  $allowed_page = true;

  session_start();

  if (!isset($_SESSION['playerId'])) {
  	throw new Exception('You must be logged!');
	exit;
  }
  
  function __autoload($className) {
    if (!isset($allowed_page)) { $allowed_page = true; }
	require_once("lib/config.php");
	require_once(CLASS_PATH."{$className}.class.php");
  }
	
  $playa=new Player();
  $playa->Load($_SESSION['playerId']);	
	
  if (isset($_POST['name']) && isset($_POST['gender'])) {   
    //TODO: Validations about special chars.
    //Retrieving fields
    $charname = $_POST['name'];
    $avatar = "Novice";  // 初新者
    $newCharacter = new Character();
	$gender = intval($_POST['gender']);	
	if($avatar=="") {
		//TODO	
	}
	
    if($message = $newCharacter->create($charname, $gender, $avatar)) {	
		if($message=="1") {
			header("Location: select_character.php");
		}
    }	
  }
  
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link type="text/css" rel="stylesheet" href="../css/global.css">
  <link type="text/css" rel="stylesheet" href="../css/portal.css">
  <link type="text/css" rel="stylesheet" href="../css/select_character.css">
  <title>D5Power WebGame Engine - 用户中心</title>

</script>
<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
</head>


<body>

<div id="main_top">
</div>


<div id="container_principal">

  <div id="textura_lateral_esquerda">

	<!-- IN�CIO - Menu lateral -->
	<div class="menu">
	  <div class="menu_esquerda"></div>
	  <div class="menu_direita"></div>
	  <div class="menu_inferior"></div>
	  <div class="menu_superior"></div>

	  <p class="itens_menu">
	    <img border="0" src="../pictures/portal/menu_hover_icon.gif" align="top" width="16" height="17">
	    <b><a href="index.php">主页</a></b><br>

	    <img border="0" src="../pictures/portal/menu_line.gif" width="122" height="5"><br>

	    <img border="0" src="../pictures/portal/menu_hover_icon.gif" align="top" width="16" height="17">
	    <b><a href="login.php">登录</a></b><br>

	    <img border="0" src="../pictures/portal/menu_line.gif" width="122" height="5"><br>

	    <img border="0" src="../pictures/portal/menu_hover_icon.gif" align="top" width="16" height="17">
	    <b><a href="register.php">注册新帐户</a></b><br>

	    <img border="0" src="../pictures/portal/menu_line.gif" width="122" height="5"><br>
	  </p>
	</div>
	<!-- FIM - Menu lateral -->


    <div id="barra_lateral_esquerda">
    </div>

  </div>
  <!-- fim do quadro textura lateral -->


	<!-- In�cio do quadro main -->
    <div id="main" style="width:645px">
    	
		<p style="text-align: center;">欢迎回来！ <?php print($playa->getUsername()); ?>！</p>

		<div class="form_header">
			<p><img style="vertical-align: middle;" src="../pictures/portal/header_left.gif"> 创建一个新的角色</p>
		</div>
		
		<div class="form_square">
          <div class="lateral_esquerda"></div>
		  <div class="lateral_direita"></div>
		  <div class="linha_inferior"></div>
		  <div class="linha_superior"></div>
		  <div style="padding: 10px;">
		
			<?php
			  if (isset($message)) {
			  	print("<p style=\"text-align: center;\">".$message."</p>");
			  }
			  else {
			?>
 	        <p style="text-align: center;">
			  <b>请填写以下内容来创建您的角色</b>
			</p>

        	<form method="POST" name="create_character" action="create_character.php">
	
              <p style="text-align: left; text-indent: 165px;">
              	角色名：
                <input name="name" type="text" class="text" id="user" style="width: 200px;" size="18" maxlength="18">
              </p>			
			
              <p align="center" style="text-align: left; text-indent: 156px;">请选择角色的性别：</p>
			  
			  <table width="50" border="0" align="center">
                <tr>
                  <td><img src="../pictures/gender/boy.gif" ><input type="radio" name="gender" value="1"></td>
                  <td><img src="../pictures/gender/girl.gif"><input type="radio" name="gender" value="0"></td>
                </tr>
              </table>
			  <p style="text-align: left; text-indent: 156px;"><a href="select_character.php"></a></p>

			  <p style="text-align: center;">
                <input type="submit" name="btn_submit" value="创建">
			  </p>
			
			</form>  
			
			<?php
			  }
			?>
			
		  </div>
		
		</div>
	  		
    </div>
	<!-- fim do quadro main -->

    <div id="textura_lateral_direita">
      <div id="barra_lateral_direita">
      </div>
    </div>

</div>

</body>
</html>
